home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2614.ZIP / TBROWS.ZIP / TTBR7.PRG < prev    next >
Text File  |  1990-10-26  |  3KB  |  167 lines

  1. /*****
  2.  *
  3.  * TTBR7.PRG
  4.  * Seventh example for TBROWSE class using a database file
  5.  *
  6.  * 21 October 90
  7.  * Luiz Quintela - Nantucket Corp
  8.  *
  9.  * Clipper ttbr7 /N/W/A/B
  10.  * RTLINK FILE ttbr7 PLL base50
  11.  *
  12.  */
  13.  
  14. // Include Header Files
  15. #include "inkey.ch"
  16. #include "setcurs.ch"
  17.  
  18. FUNCTION Main()
  19. LOCAL b, column, nKey, aColors, bData
  20. SET SCOREBOARD OFF
  21. SET DATE       BRITISH
  22. SET CONFIRM    ON
  23.  
  24. USE test INDEX test NEW
  25. // Turn cursor off
  26. SETCURSOR(SC_NONE)
  27. SETCOLOR( "BG/B" ); CLS
  28.  
  29. b := TBrowseDB( 2, 2, 20, 48)
  30. b:colorSpec := "BG/B,GR+/R,W/N,N,GR+/W,N/B,R+/B,GR+/B"
  31.  
  32. b:colSep := " │ "
  33. b:headSep := "═╤═"
  34. b:footSep := "═══"
  35.  
  36. // TBColumn objects
  37. column := TBColumnNew( "Field 1", {|| test->fld1} )
  38. column:footing := "First"
  39. b:addColumn( column )
  40. column := TBColumnNew( "Field 2", {|| test->fld2} )
  41. b:addColumn( column )
  42. column := TBColumnNew( "Field 3", {|| test->fld3} )
  43. b:addColumn( column )
  44. column := TBColumnNew( "Field 4", {|| test->fld4} )
  45. b:addColumn( column )
  46. column := TBColumnNew( "Field 5", {|| test->fld5} )
  47. column:footing := "Last"
  48. b:addColumn( column )
  49.  
  50. // Freeze one column 
  51. b:freeze := 1
  52.  
  53. // cargo
  54. // is an instance variable of ANY DATA TYPE, allowing
  55. // arbitrary information to be attached to a TBrowse object and
  56. // retrieved later
  57. // This is the same principle used in TBColumn:cargo
  58. // But now we will use TBrowse:cargo
  59. b:cargo := {|| ChangeIt() }
  60.  
  61. WHILE .T.
  62.    IF  ( b:colPos <= 1 )
  63.        b:colPos := b:freeze + 1
  64.  
  65.    ENDIF
  66.  
  67.    // Stabilization
  68.    WHILE ( !b:stabilize() )
  69.       nKey := InKey()
  70.       IF ( nKey != 0 )
  71.          EXIT // abort if a key is waiting
  72.  
  73.       ENDIF
  74.  
  75.    END
  76.  
  77.    IF ( b:stable )
  78.       IF ( b:hitTop .OR. b:hitBottom )
  79.           TONE(87.3,1)
  80.          TONE(40,3.5)
  81.  
  82.       ENDIF
  83.       nKey := INKEY(0)         
  84.  
  85.    ENDIF
  86.  
  87.    // Process key
  88.     IF ( nKey == K_DOWN )
  89.       b:down()
  90.  
  91.    ELSEIF ( nKey == K_UP )
  92.       b:up()
  93.  
  94.    ELSEIF ( nKey == K_PGDN )
  95.       b:pageDown()
  96.  
  97.    ELSEIF ( nKey == K_PGUP )
  98.       b:pageUp()
  99.  
  100.    ELSEIF ( nKey == K_CTRL_PGUP )
  101.       b:goTop()
  102.  
  103.    ELSEIF ( nKey == K_CTRL_PGDN )
  104.       b:goBottom()
  105.  
  106.    ELSEIF ( nKey == K_RIGHT )
  107.       b:right()
  108.  
  109.    ELSEIF ( nKey == K_LEFT )
  110.       b:left()
  111.  
  112.    ELSEIF ( nKey == K_HOME )
  113.       b:home()
  114.  
  115.    ELSEIF ( nKey == K_END )
  116.       b:end()
  117.  
  118.    ELSEIF ( nKey == K_CTRL_LEFT )
  119.       b:panLeft()
  120.  
  121.    ELSEIF ( nKey == K_CTRL_RIGHT )
  122.       b:panRight()
  123.  
  124.    ELSEIF ( nKey == K_CTRL_HOME )
  125.       b:panHome()
  126.  
  127.    ELSEIF ( nKey == K_CTRL_END )
  128.       b:panEnd()
  129.  
  130.    ELSEIF ( nKey == K_ESC )
  131.         CLS; SETCURSOR(SC_NORMAL); QUIT
  132.  
  133.     ELSEIF ( nKey == K_F10 )
  134.        b:setColumn( 5, EVAL( b:cargo ) )
  135.  
  136.         b:configure()   // Causes the TBrowse object to 
  137.         // re-examine all instance variables and TBColumn 
  138.         // objects, and them reconfigure its internal settings
  139.         // as required
  140.         b:refreshAll()  // Internally marks all data rows as
  141.         // invalid, causing them to be refilled and redisplayed
  142.         // during the next stabilize loop
  143.  
  144.     ENDIF
  145.  
  146. END
  147.  
  148.  
  149. FUNCTION ChangeIt()
  150. LOCAL  column
  151. STATIC IsFld5 := .T.
  152. IF IsFld5
  153.    IsFld5 := .F.
  154.    column := TBColumnNew( "Field 7", {|| test->fld7} )
  155.    column:footing := "Last"
  156.  
  157. ELSE
  158.     IsFld5 := .T.
  159.    column := TBColumnNew( "Field 5", {|| test->fld5} )
  160.    column:footing := "Last"
  161.  
  162. ENDIF
  163. RETURN column
  164.  
  165.  
  166. /* EOF - TBBR7.PRG */
  167.